<script setup lang="ts">
import Detail from './components/Detail.vue'
import { ContentDetailWrap } from '@/components/ContentDetailWrap'
import { reactive, onMounted, ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useRouter, useRoute } from 'vue-router'
import { purchaseDetail } from '@/api/common'

const { push } = useRouter()

const { query } = useRoute()

const { t } = useI18n()

const route = useRoute()
const currentRow: any = reactive({})
const detailTableData: any = reactive([])
const showDetail: any = ref(false)
let detailSchema: any = reactive([])
onMounted(() => {
  detailSchema = JSON.parse(query.detailSchema as any)
  getTableDet()
})

const getTableDet = async () => {
  const res = await purchaseDetail(query.id as string)
  if (res) {
    console.log('---获取row内容---')
    currentRow.value = res.data
    let goodsStr = currentRow.value.goods.replace(/&quot;/g, '"')
    let goodsArr: any = JSON.parse(goodsStr)
    goodsArr.forEach((item, i) => {
      let pieceItem = {
        key: i + 1,
        title: `${t('warehousingEntryAddWrite.goodsEntry')} ${i + 1} ：`,
        gname: item.gname,
        goods_id: item.goods_id,
        worth: item.worth,
        price: item.price,
        quantity: item.quantity,
        room: item.room,
        colour: item.colour,
        length: item.length,
        width: item.width,
        high: item.high,
        weight: item.weight,
        remark: item.remark,
        total: item.total
      }
      detailTableData.push(pieceItem)
    })

    showDetail.value = true
  }
}
</script>

<template>
  <ContentDetailWrap title="详情" @back="push('/salesModule/purchaseOrder')">
    <!-- <Write ref="addWriteRef" :current-row="currentRow" /> -->
    <Detail
      v-if="showDetail > 0"
      :detail-schema="detailSchema"
      :current-row="currentRow"
      :table-data="detailTableData"
    />
  </ContentDetailWrap>
</template>
